package cn.golxen.rsms;

import cn.golxen.rsms.bean.entity.StoreMain;
import cn.golxen.rsms.bean.entity.StoreOffers;
import cn.golxen.rsms.config.WechatPayConfig;
import cn.golxen.rsms.service.StoreService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cache.annotation.EnableCaching;

import java.util.List;


@SpringBootApplication
@MapperScan(value = "cn.golxen.rsms.mapper")
@Slf4j
public class RsmsApplication {

    public static void main(String[] args) {
        SpringApplication springApplication=new SpringApplication(RsmsApplication.class);
        springApplication.addListeners((ApplicationReadyEvent event)->{

            List<StoreMain> storeMainList=event.getApplicationContext().getBean(StoreService.class).getWechatPayConfig();
            event.getApplicationContext().getBean(WechatPayConfig.class).reloadWechatPayConfig(storeMainList);
            log.info("WechatPayConfig加载完成");

            event.getApplicationContext().getBean(StoreService.class).reloadStoreOffersRuing();
            log.info("StoreOffersRuing加载完成");

        });
        springApplication.run(args);
//        SpringApplication.run(RsmsApplication.class, args);
    }

}
